/**
 * Event is an abstract class for event declaration.
 * You may use it to add or remove listener in order implement
 * an Observer pattern.
 *
 * @param name	The event's registration name.
 *
 * @extends IObject
 */
function	Event(name)
{
    this.base		= IObject;
    this.base(name);

    this._type		= 'Event';

    this._listeners	= new Object();


    this.addListener		= function(listener)
    {
        if (listener && listener.getId)
        {
            this.getListeners()[listener.getId()] = listener;
        }
    }

    this.removeListener		= function(listener)
    {
        if (listener && listener.getId)
        {
            if (this.getListeners()[listener.getId()])
            {
                delete this.getListeners()[listener.getId()];
            }
        }
    }

    this.removeListenerById	= function(listenerId)
    {
        if (listenerId)
        {
            if (this.getListeners()[listenerId])
            {
                delete this.getListeners()[listener.getId()];
            }
        }
    }

    this.removeAllListeners	= function()
    {
        for (var id in this.getListeners())
        {
            delete this.getListeners()[id];
        }
    }

    this.getListeners		= function()
    {
        return (this._listeners);
    }

    this.fire				= function(args)
    {
        for (var id in this.getListeners())
        {
            if (this.getListeners()[id] && this.getListeners()[id].notify)
            {
                this.info = {
                        'source'	: '',
                        'timestamp'	: '',
                        'args'		: args
                    }
                this.getListeners()[id].notify(this);
                delete this.info;
            }
        }
    }


    //	saving a global access reference to the event
    if (!Event.list[this.getName()])
    {
        Event.list[this.getId()] = this;
    }
} // !Event
Event.prototype	= new IObject;
Event.list		= new Object();

if ((typeof(jssl) != 'undefined') && jssl && (jssl != null))
{
    if ((typeof(jssl.event) != 'undefined') && jssl.event)
    {
        jssl.event.Event = Event;
    }
    else
    {
        jssl.event	=
        {
            Event	: Event
        };
    }
}
else
{
    jssl	=
    {
        event	:
        {
            Event	: Event
        }
    };
}
